<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>部门维护</title>
    <style>
        .fail .layui-layer-content {
            background-color: brown;
            color: #eee;
            width: 480px;
            height: 30px;
            text-align: center;
        }

        .succeed .layui-layer-content {
            background-color: #0061A8;
            color: #eee;
            width: 400px;
            height: 30px;
            text-align: center;
        }
    </style>
</head>
<body>
<div id="app">
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i>首页
        <span class="c-gray en">&gt;</span> {{oneTitle}}
        <span class="c-gray en">&gt;</span> {{towTitle}}
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" @click="fRefresh()" title="刷新">
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
    </nav>
    <div class="page-container">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <label style=" margin-top: 6px; margin-right: 6px" class="l">选择组织：
                <select id="jflx" style="width: 260px; font-size: 15px;" v-model="bCode" @change='getValue'>
                </select>
            </label>
            <span class="l">
                <a href="javascript:" @click="fAdd" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 新增部门</a>
                <span class="r" style="padding-top: 6px;">共有数据：[<strong id="count">{{iiCount}}</strong> 条]</span>
            </span>
        </div>
        <table style="table-layout:fixed; width: 100%; word-break:break-all;" class="table table-border table-bordered table-bg table-hover table-sort table-responsive" id="tablelist">
            <span class="l" style="padding-top: 6px;">组织部门列表</span>
            <thead>
            <tr class="text-c" style="height:0px;">
                <th style="width: 100px">部门编号</th>
                <th style="width: 300px">部门名称</th>
                <th style="width: 120px">排序号</th>
                <th style="width: 160px">创建时间</th>
                <th style="width: 120px">操作员</th>
                <th style="width: 180px">消费类别</th>
                <th>操作</th>
            </tr>
            </thead>

            <tbody id="datalist">
            <tr class='text-c' v-for="item in tableData" :key="item.VALUE01" v-cloak>
                <td> {{item.VALUE01}}</td>
                <td> {{item.VALUE02}}</td>
                <td> {{item.VALUE03}}</td>
                <td> {{item.VALUE04}}</td>
                <td> {{item.VALUE05}}</td>
                <td> {{item.VALUE06}}</td>
                <td class='td-manage'>
                    <input class="btn btn-secondary-outline radius" type="button" value="编辑" @click="adminEdit('部门信息修改',item,'800','400', 'UPDATE')">
                    <input class="btn btn-danger-outline radius" type="button" value="删除" @click="fDel(item)">
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="static/axios.min.js"></script>
<script type="text/javascript" src="./static/vue"></script>

<script type="text/javascript">
    let vm = new Vue({
        el: '#app',
        data: {
            oneTitle: '人事管理',
            towTitle: '组织部门维护',
            ii_page: 1,   //--上一页下一页的计数器
            ii_row: 20,   //--每页显示的记录数
            iiCount: 0,
            is_search: '',
            tableData: [],
            jflx: [],
            xflx: [],
            bCode: '',
            bName: ''
        },
        methods: {
            getValue() {
                this.bName = $("#jflx").find('option:selected').text();
                this.fGetinfo()
            },

            fDel(obj){
                let self = this
                layer.confirm('<span style="font-size:22px;' +
                    'line-height: 30px;' +
                    ' color: brown;">请确定是否删除该部门信息！' +
                    '</span>',
                    {
                        title:['信息确认', 'font-size:16px; font-weight:blod; background:brown; color:#eee'],
                        area:['450px','190px'], //弹框的大小
                        btn: ["确定", "取消"] //按钮
                    }, function () {
                        if (!this.lock) {
                            this.lock = true
                            let params = new URLSearchParams();
                            params.append('CMD', "CE");
                            params.append('VALUE01', obj.VALUE01);
                            axios.post('/f_wscl/com2', params)
                                .then(function (res) {
                                    let {db1} = res.data
                                    if (db1[0].VALUE01 === 'ZZ01') {
                                        layer.msg('<span style="font-size:26px; line-height: 30px">' + db1[0].VALUE02 + '</span>', {time: 2000, skin: 'fail'});
                                    } else if (db1[0].VALUE01 === 'ZZ00') {
                                        layer.msg("<span style='font-size:26px; line-height: 30px'>部门删除完毕!</span>", {time: 2000, skin: 'succeed'}, function () {
                                            let index = parent.layer.getFrameIndex(window.name);
                                            self.fGetinfo();
                                            parent.layer.close(index);
                                        });
                                    }
                                })
                                .catch(function (error) {
                                    layer.msg('<span style="font-size:26px; line-height: 30px">网络异常错误!</span>', {time: 1500, skin: 'fail'});
                                })
                                .finally(function () {
                                    self.lock = false
                                });
                        }
                        //--如下两个备注留着，用来确定是否关闭弹出的界面而不关闭显示流水的列表界面
                        // layer.closeAll('dialog');
                        // layer.close(index);
                    }, function () {
                    });
            },


            fAdd() {
                //--首先获取最大的编号，虽然获取的编号是个虚的
                if (this.bCode.length === 0) {
                    layer.msg('请先选择组织!', {icon: 0, time: 2000});
                    return
                }
                let ls_opid = "${sessionOpid}";
                let self = this
                let params = new URLSearchParams();
                params.append('CMD', "AG");
                params.append('VALUE01', ls_opid);

                axios.post('/f_wscl/com2', params)
                    .then(function (res) {
                        let {db1} = res.data
                        self.adminEdit('部门信息新增', db1[0], '800', '400', 'INSERT')
                    })
                    .catch(function (error) {
                        layer.msg('网络异常错误', {icon: 1, time: 1000});
                    });
            },

            fRefresh() {
                this.fGetinfo();
            },

            fGetinfoGs() {
                let ls_opid = "${sessionOpid}";
                let self = this
                let params = new URLSearchParams();
                params.append('CMD', "AJ");
                params.append('VALUE01', ls_opid);

                axios.post('/f_wscl/com2', params)
                    .then(function (res) {
                        //--db1主界面显示数据  db2显示总数据条数  db3消费类型下拉列表
                        let {db1, db3} = res.data
                        self.jflx = db1
                        self.xflx = db3
                        let cjflx = $("#jflx")
                        cjflx.append("<option value=''></option>");
                        for (let i = 0; i < self.jflx.length; i++) {
                            cjflx.append("<option value='" + self.jflx[i].VALUE01 + "'>" + self.jflx[i].VALUE03 + "</option>");
                        }
                    })
                    .catch(function (error) {
                        layer.msg('网络异常错误', {icon: 1, time: 1000});
                    });
            },

            fGetinfo() {
                let self = this
                let params = new URLSearchParams();
                params.append('CMD', "ZM");
                params.append('VALUE01', this.bCode);

                axios.post('/f_wscl/com2', params)
                    .then(function (res) {
                        //--db1主界面显示数据  db2显示总数据条数  db3消费类型下拉列表
                        let {db1, db2} = res.data
                        self.tableData = db1
                        self.iiCount = db2[0].VALUE01
                    })
                    .catch(function (error) {
                        layer.msg('网络异常错误', {icon: 1, time: 1000});
                    });
            },

            /*编辑和新增*/
            //--   jud=INSERT UPDATE
            adminEdit(title, obj, w, h, jud) {
                if (title == null || title === '') {
                    title = false;
                }
                if (w == null || w === '') {
                    w = 800;
                }
                if (h == null || h === '') {
                    h = ($(window).height() - 50);
                }
                let ls_opid = "${sessionOpid}";
                let self = this
                layer.open({
                    type: 2,
                    area: [w + 'px', h + 'px'],
                    fix: false, //不固定
                    maxmin: false,
                    shade: 0.4,
                    title: title,
                    content: ['w_zxkj_bmwhedit.jsp', 'no'],
                    success: function (layero, index) {
                        let body = layer.getChildFrame('body', index);//少了这个是不能从父页面向子页面传值的
                        //渲染基本操作数据
                        body.contents().find("#opid").val(ls_opid);          //--操作员编号
                        body.contents().find("#do").val(jud);                //--做何种操作

                        body.contents().find("#bcode").val(self.bCode);      //--部门编号
                        body.contents().find("#bname").val(self.bName);      //--部门名称
                        body.contents().find("#bcode").css({color: "#aaa"});
                        body.contents().find("#bname").css({color: "#aaa"});

                        body.contents().find("#xflx").append("<option value=''></option>");
                        for (let i = 0; i < self.xflx.length; i++) {
                            body.contents().find("#xflx").append("<option value='" + self.xflx[i].VALUE01 + "'>" + self.xflx[i].VALUE02 + "</option>");
                        }
                        console.log(obj);
                        if (jud === 'UPDATE') {
                            body.contents().find("#bmbh").val(obj.VALUE01);
                            body.contents().find("#bmmc").val(obj.VALUE02);
                            body.contents().find("#fzr").val(obj.VALUE03);
                            body.contents().find("#xflx").find("option:contains('" + obj.VALUE06 + "')").attr("selected", true)
                        } else if (jud === 'INSERT') {
                            body.contents().find("#bmbh").val(obj.VALUE01);
                        }
                    },
                });
            }
        },
        mounted() {
            window.fwGetinfo = this.fGetinfo;
        },

        created() {
            this.fGetinfoGs()
        }
    });
</script>
</body>
</html>
